package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "护理模块相关接口")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页条件查询")
    public ResponseResult<PageResponse<NursingProjectVo>> pageQuery(String name,
                                                                    Integer status,
                                                                    @ApiParam(name = "pageNum", value = "当前页码")
                                                                    @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(name = "pageSize", value = "总条数")
                                                                    @RequestParam(required = false, defaultValue = "10") Integer pageSize) {

        PageResponse<NursingProjectVo> res = nursingProjectService.pageQuery(name, status, pageNum, pageSize);
        return success(res);
    }

    /**
     * 护理项目新增接口
     *
     * @return
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult addNursingProject(
            @ApiParam(value = "护理项目对象", required = true)
            @RequestBody NursingProjectDto dto) {

        nursingProjectService.addNursingProject(dto);
        return success();
    }

    @ApiOperation("根据id查询护理项目")
    @GetMapping("{id}")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@PathVariable Long id) {

        NursingProjectVo vo = nursingProjectService.getNursingProjectById(id);
        return success(vo);
    }

    /**
     * 修改护理项目
     * @param dto
     * @return
     */
    @ApiOperation("修改护理项目")
    @PutMapping
    public ResponseResult updateNursingProject(@ApiParam(value = "护理项目对象", required = true)
                                               @RequestBody NursingProjectDto dto) {

        nursingProjectService.updateNursingProject(dto);
        return success();
    }

    /**
     * 修改状态信息
     *
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("修改护理项目状态")
    @PutMapping("{id}/status/{status}")
    public ResponseResult updateStatus(@ApiParam(value = "主键id", required = true)
                                       @PathVariable Long id,
                                       @ApiParam(value = "状态信息: 0 禁用,1 启用 ")
                                       @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return success();
    }
    @DeleteMapping("{id}")
    @ApiOperation("删除护理项目")
    public  ResponseResult deleteNursingProject(@PathVariable Long id){
        nursingProjectService.deleteNursingProject(id);
        return  success();
    }

    /**
     * 查询全部护理项目
     * @return
     */
    @ApiOperation(value = "查询全部护理项目")
    @GetMapping("all")
    public ResponseResult<List<NursingProjectVo>> queryAllNursingProject(){

        List<NursingProjectVo> vo=nursingProjectService.queryAllNursingProject();
        return success(vo);
    }

}
